using System.Collections.Generic;
using System.Xml;

namespace Miao
{
	abstract public class PatchOperation
    {

		public string sourceFile;

		private bool succeeded = true;

		public bool Apply(XmlDocument xml)
		{

            succeeded = ApplyWorker(xml);
			return succeeded;
		}

		protected virtual bool ApplyWorker(XmlDocument xml)
		{
			Log.Error("Attempted to use PatchOperation directly; patch will always fail");
			return false;
		}

		public virtual void Complete(string modIdentifier)
		{
			if (succeeded)
			{
				string text = $"[{modIdentifier}] Patch operation {this} failed";
				if (!string.IsNullOrEmpty(sourceFile))
				{
					text = text + "\nfile: " + sourceFile;
				}
				Log.Error(text);
			}
		}

		public virtual IEnumerable<string> ConfigErrors()
		{
			yield break;
		}

	
    }
}
